import 'package:common/common.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:miaowu/app/common/window_pop/public_btn_tem.dart';

import 'member_config.dart';

class MemberPayWidget extends StatefulWidget {
  const MemberPayWidget({super.key, required this.sec41, required this.price});
  final Sec41 sec41;
  final String price;

  @override
  State<MemberPayWidget> createState() => _MemberPayWidgetState();
}

class _MemberPayWidgetState extends State<MemberPayWidget> {
  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  PayChannels? choosePayChannel;
  @override
  Widget build(BuildContext context) {
    PublicBtnItem? btnItem = widget.sec41.btns?.first;

    return Container(
      height: 450,
      decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.only(topLeft: Radius.circular(16.r), topRight: Radius.circular(16.r))),
      child: Stack(
        children: [
          Image.asset('assets/app/images/member/member_pay_bg.png'),
          Container(
            color: Colors.transparent,
            child: Column(
              children: [
                Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 1, vertical: 13),
                  child: OverflowBar(
                    alignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Expanded(
                        child: TextButton(
                          onPressed: () => Navigator.pop(context),
                          child: Image.asset('assets/app/images/member/member_pay_close.png', width: 15.sp),
                        ),
                      ),
                      Expanded(child: Text('支付方式', style: TextStyle(color: const Color(0xFF000000), fontSize: 17.sp))),
                      const Expanded(child: SizedBox(width: 60)),
                      // TextButton(
                      //   onPressed: () {
                      //     Navigator.pop(context);
                      //   },
                      //   child: const Text('确定', style: TextStyle(color: Color(0xFF25D4D0), fontSize: 17)),
                      // ),
                    ],
                  ),
                ),
                Text(widget.price, style: TextStyle(color: const Color(0xFF000000), fontSize: 44.sp)),
                Expanded(
                  child: ListView.builder(
                    padding: const EdgeInsets.symmetric(horizontal: 23, vertical: 20),
                    itemBuilder: (BuildContext cxt, int index) {
                      PayChannels payChannel = widget.sec41.payChannels![index];
                      return Container(
                          margin: EdgeInsets.only(bottom: 16.h),
                          padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
                          decoration:
                              BoxDecoration(color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(19.r))),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Row(
                                children: [
                                  Image.asset('assets/app/images/member/member_pay_wechat.png', width: 40),
                                  const SizedBox(width: 8),
                                  Text(payChannel.chnName ?? '',
                                      style: TextStyle(color: Colors.black, fontSize: 15.sp)),
                                ],
                              ),
                              Padding(
                                  padding: const EdgeInsets.only(top: 2),
                                  child: Image.asset(
                                      choosePayChannel != null && choosePayChannel!.chnId == payChannel.chnId
                                          ? 'assets/app/images/auth/auth_check_s.png'
                                          : 'assets/app/images/auth/auth_check_n.png',
                                      width: 15.0.w))
                            ],
                          )).onTap(() {
                        choosePayChannel = payChannel;
                        setState(() {});
                      });
                    },
                    itemCount: widget.sec41.payChannels!.length,
                  ),
                ),
                if (btnItem != null && btnItem.view == 1)
                  Container(
                    height: 51,
                    margin: const EdgeInsets.only(left: 20, right: 20, top: 20),
                    alignment: Alignment.center,
                    decoration: BoxDecoration(color: const Color(0xFF25D4D0), borderRadius: BorderRadius.circular(25)),
                    child: Text(
                      btnItem.title ?? '',
                      style: TextStyle(color: Colors.white, fontSize: 16.sp, fontWeight: FontWeight.w600),
                    ),
                  ),
                SizedBox(height: AppScreen.safeAreaPaddingBottom)
              ],
            ),
          ),
        ],
      ),
    );
  }
}
